﻿using System;
using System.Drawing;
using ZXing;
using ZXing.Common;
using ZXing.QrCode;
using System.Drawing.Imaging;
namespace UcAsp.Net.Comm
{
    public class CreateQr
    {
        private EncodingOptions options = null;
        private BarcodeWriter writer = null;

        public CreateQr(int width, int height)
        {
            options = new QrCodeEncodingOptions
                {
                    DisableECI = true,
                    CharacterSet = "UTF-8",
                    Width = width,
                    Height = height
                };
            writer = new BarcodeWriter();
            writer.Format = BarcodeFormat.QR_CODE;
            writer.Options = options;
        }

        public Bitmap GetBitmap(string code)
        {
            System.Drawing.Bitmap bitmap = writer.Write(code);            
            return bitmap;
        }
        public bool CreateQrFile(string code,string savepath,string fileid)
        {
            bool result=false;
             System.Drawing.Bitmap bitmap = writer.Write(code);
            try{
                ImageQuality image=new ImageQuality();
                image.SaveAsJPEG(bitmap,savepath+fileid+".jpg",85);
                result=true;
            }
            catch{
            
            }
            return result;
        }
    }
}
